<script setup>
import {http} from "@/api";
import {ref} from "vue";
import {ElMessage} from "element-plus";
const code = ref('')
const detail = ref({
  code: ''
})
const search = () => {
  if (!code.value) return ElMessage.error('请输入券码')
  http.GiftSendItem.read(code.value).then(res => {
    detail.value = {
      ...res.data,
      member: res.data.member || {}
    }
    if (!res.data.member) return ElMessage.error('未找到用户')
  })
}
const reset = () => {
  if (detail.value.id && detail.value.is_use === 1) {
    http.GiftSendItem.update({
      id: detail.value.id,
      gift_id: detail.value.gift_id,
      is_use: 0
    }).then(res => {
      console.log(res)
    })
  }
}
</script>


<template>
  <PageMain title="礼品核销">
    <el-form label-suffix="" inline style="width: 300px;margin: 200px auto" label-width="120px">
      <el-form-item label="券码">
        <el-input v-model="code" placeholder="请输入"></el-input>
      </el-form-item>
      <div v-if="detail.id">
        <el-form-item label="用户名" >
          {{ detail.member.username }}
        </el-form-item>
        <el-form-item label="手机号" disabled>
          {{ detail.member.phone }}
        </el-form-item>

        <el-form-item label="礼品名称" disabled>
          {{ detail.gift.name }}
        </el-form-item>
        <el-form-item label="库存" disabled>
          {{ detail.gift.store_count }}
        </el-form-item>
        <el-form-item label="是否核销">
          <el-tag :type="detail.is_use === 0 ? 'success' : 'error'">{{ detail.is_use === 0 ? '已核销' : '未核销' }}</el-tag>
        </el-form-item>
      </div>
      <el-form-item label=" ">
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="reset" v-if="detail.is_use === 1">核销</el-button>
      </el-form-item>
    </el-form>
  </PageMain>
</template>

<style scoped lang="scss">

</style>
